package com.chen.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class ChannelReadTest {
    public static void main(String[] args) throws IOException {
        File file = new File("D:/a.txt");
        FileInputStream fileInputStream = new FileInputStream(file);
        //实际上是实现类在起作用
        FileChannel channel = fileInputStream.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());
        //将通道的数据写入buffer
        channel.read(byteBuffer);
        String s = new String(byteBuffer.array());
        System.out.println(s);

    }
}
